import typing
from typing import Optional

import PySide6.QtCore
from PySide6.QtGui import QIcon
import PySide6.QtWidgets
from PySide6.QtCore import Qt

from ..LittleWidgetBase import LittleWidgetBase
from .Ui_LWCheckBox import Ui_LWCheckBox

class LWCheckBox(LittleWidgetBase):
    def __init__(
        self, 
        parent: Optional[PySide6.QtWidgets.QWidget] = None, 
        f: PySide6.QtCore.Qt.WindowFlags = Qt.Widget) -> None:
        ################################################
        super().__init__(parent=parent, f=f)
        self._ui = Ui_LWCheckBox()
        self._ui.setupUi(self)
        self._propertys.update({
            'checkState': 0,
        })
        self._ui.checkBox.stateChanged.connect(self._SlotCheckStateChanged)

    def UpdateProperty(self, key: 'str', value: typing.Any) -> None:
        super().UpdateProperty(key, value)
        if (key not in self._propertys.keys()):
            return
        if (key == 'checkState'):
            if (not isinstance(value, int)):
                return
            self._ui.checkBox.setCheckState(Qt.CheckState(value))

    def _SlotCheckStateChanged(self, state: 'int') -> None:
        '''
        function:
            当 CheckState 变的时候做什么
        '''
        self._UpdatePropertyValue({'checkState': state})
        self.signalEvent.emit(self.EventCheckChanged, self)
        